#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

pthread_t g_id = 0;
void* thread_run(void* args)
{
  pthread_detach(pthread_self());
  const char* s = (const char*)args;
  printf("%s %lu\n", s, pthread_self());
  // pthread_cancel(g_id);
  int cnt = 5;
  while(cnt--)
  {
    printf("new thread \n");
    sleep(1);
  }
  //pthread_exit((void*)123);
  //return (void*)111;
}
int main()
{
  g_id = pthread_self();
  pthread_t tid;
  pthread_create(&tid, NULL, (void*)thread_run, "thread_1");
  
  //pthr1ead_cancel(tid);
  while(1) {
    printf("i am main thread:%lu\n", pthread_self());
    void *status = NULL;
    int r = pthread_join(tid, &status);
    printf("ret:%d join_r:%d\n",(int)status, r);
    sleep(2);
  }
  return 0;
}
